package org.example.springboot.controller;


import org.example.springboot.model.Products;
import org.example.springboot.service.ProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
public class ProductController {
    @Autowired
    private ProductsService productsService;

    @PostMapping("/insertProduct")
    public String insertProduct(@RequestBody Products products){
        return productsService.insertProduct(products.getProductImage(),products.getProductName(),products.getSerialNumber(),products.getModelNumber(),products.getServiceCode(),products.getSupplierName(),products.getCategory(),products.getPurchasePrice(),products.getSalePrice(),products.getWarrantyPeriod(),products.getStatus(),products.getStock(),products.getInOrderId(),products.getOutOrderId(),products.getCustomerName(),products.getProjectName(),products.getSalesTeam(),products.getAfterSalesTeam(),products.getNotes());
    }

    @GetMapping("/getAllProduct")
    public List<Products> getAllProduct(){
        return productsService.getAllProduct();
    }

    @GetMapping("/findProductByKeyword/{keyword}")
    public List<Products> findProductByKeyword(@PathVariable String keyword){
        return productsService.findProductByKeyword(keyword);
    }

    @GetMapping("/getProductById/{id}")
    public Products getProductById(@PathVariable int id){
        return productsService.getProductById(id);
    }

    @DeleteMapping("/deleteProductById/{id}")
    public void deleteProductById(@PathVariable int id){
        productsService.deleteProductById(id);
    }

    @PostMapping("/updateProductStock/{id}/{stock}")
    public void updateProductStock(@PathVariable int id,@PathVariable String stock){
        productsService.updateProductStock(stock,id);
    }

    @PostMapping("/updateProduct/{id}")
    public void updateProduct(@PathVariable int id,@RequestBody Products products){
       productsService.updateProduct(id,products);
    }

}
